import request from '@/utils/request'
import * as tool from '@/utils/tools'
import * as URL from '@/constants/api'
// 获取角色列表
export function getRoles(params) {
  return request({
    url: URL.ROLE_LIST,
    method: 'GET',
    params
  }).then(res => res.data.data)
}
// 根据id删除角色
export function deleteRole(id) {
  return request({
    url: URL.CHANGE_ROLE + id,
    method: 'DELETE'
  }).then(res => res.data)
}
// 添加角色
export function addRole(data) {
  return request({
    url: URL.ROLE_LIST,
    method: 'POST',
    data
  }).then(res => res.data)
}
// 根据id更新角色
export function editRole(data) {
  return request({
    url: URL.CHANGE_ROLE + data.id,
    method: 'PUT',
    data
  }).then(res => res.data)
}
// 根据ID获取角色详情 根据ID获取角色权限详情
export function getOneRole(id) {
  return request({
    url: URL.CHANGE_ROLE + id,
    method: 'GET'
  }).then(res => res.data.data.permIds)
}
// 获取所有权限点
export function getPermissionList() {
  return request({
    url: URL.GET_PERMISSION,
    method: 'GET'
  }).then(res => tool.getTreeData(res.data.data))
}
// 给角色分配权限
export function assignPermission(data) {
  return request({
    url: URL.ASSIGN_PERMISSION,
    method: 'PUT',
    data
  }).then(res => res.data)
}
